package com.fy56.platform.logistics.common;

public class ResultModel<T> {

    /**
     * 返回码
     */
    protected Integer code;

    /**
     * 返回结果描述
     */
    protected String msg;

    /**
     * 返回值
     */
    protected T content;

    /**
     * 子业务返回状态
     */
    protected  ResultModel subResultModel;

    public ResultModel() {
    }

    public ResultModel(String msg) {
        this.code = 0;
        this.msg = msg;
        this.content = null;
    }

    public ResultModel(boolean isSuccess) {
        if(isSuccess){
            this.code = ResultStatus.SUCCESS.getCode();
            this.msg = ResultStatus.SUCCESS.getMessage();
        }else{
            this.code = 101;
            this.msg = "失败";
        }
        this.content = null;
    }

    public ResultModel(Integer code, String msg, T content) {
        this.code = code;
        this.msg = msg;
        this.content = content;
    }

    public ResultModel(ResultStatus status) {
        this.code = status.getCode();
        this.msg = status.getMessage();
        this.content = null;
    }

    public ResultModel(ResultStatus status, T content) {
        this.code = status.getCode();
        this.msg = status.getMessage();
        this.content = content;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getContent() {
        return content;
    }

    public static ResultModel ok(Object content) {
        return new ResultModel(ResultStatus.SUCCESS, content);
    }

    public static ResultModel ok() {
        return new ResultModel(ResultStatus.SUCCESS);
    }

    public static ResultModel error(ResultStatus error, String message) {
        return new ResultModel(error, message);
    }

    public static ResultModel error(String message) {
        return new ResultModel(101, message,null);
    }

    public static ResultModel error(ResultStatus error) {
        return new ResultModel(error);
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setContent(T content) {
        this.content = content;
    }

    public ResultModel getSubResultModel() {
        return subResultModel;
    }

    public void setSubResultModel(ResultModel subResultModel) {
        this.subResultModel = subResultModel;
    }
}
